/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaInicial.java
 *
 * Created on 03/12/2011, 12:30:15
 */
package br.uff.ihc.gui;

import br.uff.ihc.bd.entidades.Paciente;
import br.uff.ihc.bd.tabelas.TB_Paciente;
import br.uff.ihc.regras_negocio.RN_Paciente;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import java.util.Random;
import javax.swing.BorderFactory;


import javax.swing.JOptionPane;

import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Adrielle
 */
public class TelaPacientes extends javax.swing.JFrame {
    private TB_Paciente pacientes;
    private Paciente p;

    String nome;
    /** Creates new form TelaInicial */
    public TelaPacientes(String nome) {
        initComponents();

        Insets in = Toolkit.getDefaultToolkit().getScreenInsets(this.getGraphicsConfiguration());
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        int width = d.width - (in.left + in.top);
        int height = d.height - (in.top + in.bottom);
        setSize(width, height);
        setLocation(in.left, in.top);
        setExtendedState(TelaPacientes.MAXIMIZED_BOTH);
        pnBTBuscarPaciente.setBackground(new Color(0, 51, 0));
        pnBTNovoPaciente.setBackground(Color.WHITE);
        pnBTNovoPaciente.getComponent(0).setForeground(Color.BLACK);
        pnBTBuscarPaciente.getComponent(0).setForeground(Color.WHITE);
        pnBTNovoPaciente.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.BLACK));
        pnNovoPaciente.setVisible(true);
        pnBuscarPaciente.setVisible(false);
        lbMsgDigital.setVisible(false);
        lbDigital.setVisible(false);
        this.nome = nome;
        lbNomeUsuario.setText(nome);
//
//        try {
//            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (UnsupportedLookAndFeelException e) {
//        } catch (ClassNotFoundException e) {
//            // handle exception
//        } catch (InstantiationException e) {
//            // handle exception
//        } catch (IllegalAccessException e) {
//            // handle exception
//        }


       // pacientes = new TB_Paciente();
        p = new Paciente();


    }

    public void centralizarComponente(Component pai, Component filho) {
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel5 = new javax.swing.JPanel();
        lbRotuloUsuario = new javax.swing.JLabel();
        lbNomeUsuario = new javax.swing.JLabel();
        lbData = new javax.swing.JLabel();
        pnPrincipal = new javax.swing.JPanel();
        pnBTNovoPaciente = new javax.swing.JPanel();
        lbNonoPaciente = new javax.swing.JLabel();
        pnBTBuscarPaciente = new javax.swing.JPanel();
        lbBuscarPaciente = new javax.swing.JLabel();
        pnBuscarPaciente = new javax.swing.JPanel();
        lbDadosPessoais = new javax.swing.JLabel();
        txNome1 = new javax.swing.JTextField();
        lbNome1 = new javax.swing.JLabel();
        lbCPF1 = new javax.swing.JLabel();
        txCPF1 = new javax.swing.JTextField();
        lbRG1 = new javax.swing.JLabel();
        txRG1 = new javax.swing.JTextField();
        txCSC1 = new javax.swing.JTextField();
        lbCSC1 = new javax.swing.JLabel();
        lbDataNascimento1 = new javax.swing.JLabel();
        btLeitura = new javax.swing.JButton();
        btConfirmar = new javax.swing.JButton();
        btCartao = new javax.swing.JButton();
        dtDataNascimento1 = new com.toedter.calendar.JDateChooser();
        pnNovoPaciente = new javax.swing.JPanel();
        lbCPF = new javax.swing.JLabel();
        lbNome = new javax.swing.JLabel();
        lbCSC = new javax.swing.JLabel();
        lbRG = new javax.swing.JLabel();
        lbNumero = new javax.swing.JLabel();
        lbRua = new javax.swing.JLabel();
        lbComplemento = new javax.swing.JLabel();
        lbBairro = new javax.swing.JLabel();
        lbCidade = new javax.swing.JLabel();
        lbCEP = new javax.swing.JLabel();
        lbEstado = new javax.swing.JLabel();
        lbEndereco = new javax.swing.JLabel();
        txRua = new javax.swing.JTextField();
        txNumero = new javax.swing.JTextField();
        txBairro = new javax.swing.JTextField();
        txComplemento = new javax.swing.JTextField();
        txCEP = new javax.swing.JTextField();
        cbCidade = new javax.swing.JComboBox();
        cbEstado = new javax.swing.JComboBox();
        txNome = new javax.swing.JTextField();
        txCSC = new javax.swing.JTextField();
        txCPF = new javax.swing.JTextField();
        txRG = new javax.swing.JTextField();
        btCadastrarDigital = new javax.swing.JButton();
        lbDataNascimento = new javax.swing.JLabel();
        lbDadosPessoais1 = new javax.swing.JLabel();
        lbImpressaoDigital = new javax.swing.JLabel();
        lbDigital = new javax.swing.JLabel();
        lbAviso = new javax.swing.JLabel();
        lbMsgAviso = new javax.swing.JLabel();
        lbMsgDigital = new javax.swing.JLabel();
        btSalvar = new javax.swing.JButton();
        dtDataNascimento = new com.toedter.calendar.JDateChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Pacientes");

        jPanel5.setBackground(new java.awt.Color(47, 120, 47));

        lbRotuloUsuario.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 13));
        lbRotuloUsuario.setForeground(new java.awt.Color(255, 255, 255));
        lbRotuloUsuario.setText("Usuário:");

        lbNomeUsuario.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 13));
        lbNomeUsuario.setForeground(new java.awt.Color(255, 255, 255));
        lbNomeUsuario.setText("João Victor");

        lbData.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 13));
        lbData.setForeground(new java.awt.Color(255, 255, 255));
        lbData.setText("Quarta, 7 de dezembro de 2011 10:30h");

        pnPrincipal.setBackground(new java.awt.Color(255, 255, 255));
        pnPrincipal.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 51, 0), 1, true));
        pnPrincipal.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pnBTNovoPaciente.setBackground(new java.awt.Color(0, 51, 0));
        pnBTNovoPaciente.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true));
        pnBTNovoPaciente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                OnNovoPaciente(evt);
            }
        });

        lbNonoPaciente.setFont(new java.awt.Font("Papyrus", 1, 14));
        lbNonoPaciente.setForeground(new java.awt.Color(255, 255, 255));
        lbNonoPaciente.setText("Novo Paciente");

        javax.swing.GroupLayout pnBTNovoPacienteLayout = new javax.swing.GroupLayout(pnBTNovoPaciente);
        pnBTNovoPaciente.setLayout(pnBTNovoPacienteLayout);
        pnBTNovoPacienteLayout.setHorizontalGroup(
            pnBTNovoPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnBTNovoPacienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbNonoPaciente)
                .addContainerGap(22, Short.MAX_VALUE))
        );
        pnBTNovoPacienteLayout.setVerticalGroup(
            pnBTNovoPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnBTNovoPacienteLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lbNonoPaciente)
                .addContainerGap())
        );

        pnPrincipal.add(pnBTNovoPaciente, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 140, 40));

        pnBTBuscarPaciente.setBackground(new java.awt.Color(0, 51, 0));
        pnBTBuscarPaciente.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true));
        pnBTBuscarPaciente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pnBTBuscarPacienteMouseClicked(evt);
            }
        });

        lbBuscarPaciente.setFont(new java.awt.Font("Papyrus", 1, 14));
        lbBuscarPaciente.setForeground(new java.awt.Color(255, 255, 255));
        lbBuscarPaciente.setText("Buscar Paciente");

        javax.swing.GroupLayout pnBTBuscarPacienteLayout = new javax.swing.GroupLayout(pnBTBuscarPaciente);
        pnBTBuscarPaciente.setLayout(pnBTBuscarPacienteLayout);
        pnBTBuscarPacienteLayout.setHorizontalGroup(
            pnBTBuscarPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnBTBuscarPacienteLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lbBuscarPaciente)
                .addContainerGap())
        );
        pnBTBuscarPacienteLayout.setVerticalGroup(
            pnBTBuscarPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnBTBuscarPacienteLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(lbBuscarPaciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pnPrincipal.add(pnBTBuscarPaciente, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, 140, 40));

        pnBuscarPaciente.setBackground(new java.awt.Color(255, 255, 255));
        pnBuscarPaciente.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 51, 0), 1, true));
        pnBuscarPaciente.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lbDadosPessoais.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados Pessoais", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Papyrus", 0, 11), new java.awt.Color(0, 51, 0))); // NOI18N
        pnBuscarPaciente.add(lbDadosPessoais, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 200, 750, 220));

        txNome1.setEditable(false);
        pnBuscarPaciente.add(txNome1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 250, 580, -1));

        lbNome1.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbNome1.setText("Nome:");
        pnBuscarPaciente.add(lbNome1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 250, 60, -1));

        lbCPF1.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbCPF1.setText("CPF:");
        pnBuscarPaciente.add(lbCPF1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 290, 60, -1));

        txCPF1.setEditable(false);
        pnBuscarPaciente.add(txCPF1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 290, 210, -1));

        lbRG1.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbRG1.setText("RG:");
        pnBuscarPaciente.add(lbRG1, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 290, 70, -1));

        txRG1.setEditable(false);
        pnBuscarPaciente.add(txRG1, new org.netbeans.lib.awtextra.AbsoluteConstraints(640, 290, 190, -1));

        txCSC1.setEditable(false);
        pnBuscarPaciente.add(txCSC1, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 370, 220, -1));

        lbCSC1.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbCSC1.setText("Cartão de Saúde do Cidadão:");
        pnBuscarPaciente.add(lbCSC1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 370, 258, -1));

        lbDataNascimento1.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbDataNascimento1.setText("Data de Nascimento:");
        pnBuscarPaciente.add(lbDataNascimento1, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 330, 170, -1));

        btLeitura.setBackground(new java.awt.Color(255, 255, 255));
        btLeitura.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/uff/ihc/gui/imagens/mao.png"))); // NOI18N
        btLeitura.setToolTipText("Fazer a leitura biométrica");
        btLeitura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLeituraActionPerformed(evt);
            }
        });
        pnBuscarPaciente.add(btLeitura, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 40, 150, 120));

        btConfirmar.setFont(new java.awt.Font("DejaVu Sans", 0, 13)); // NOI18N
        btConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/uff/ihc/gui/imagens/visualizar.gif"))); // NOI18N
        btConfirmar.setText("Visualizar Perfil");
        btConfirmar.setToolTipText("Cofirmar Paciente");
        btConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btConfirmarActionPerformed(evt);
            }
        });
        pnBuscarPaciente.add(btConfirmar, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 430, 160, 40));

        btCartao.setBackground(new java.awt.Color(255, 255, 255));
        btCartao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/uff/ihc/gui/imagens/cartao.png"))); // NOI18N
        btCartao.setToolTipText("Buscar pelo cartão de saúde do cidadão");
        btCartao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCartaoActionPerformed(evt);
            }
        });
        pnBuscarPaciente.add(btCartao, new org.netbeans.lib.awtextra.AbsoluteConstraints(630, 40, 150, 120));
        pnBuscarPaciente.add(dtDataNascimento1, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 330, 130, -1));

        pnPrincipal.add(pnBuscarPaciente, new org.netbeans.lib.awtextra.AbsoluteConstraints(149, 60, 1180, 550));

        pnNovoPaciente.setBackground(new java.awt.Color(255, 255, 255));
        pnNovoPaciente.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 51, 0), 1, true));
        pnNovoPaciente.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lbCPF.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbCPF.setText("CPF:");
        pnNovoPaciente.add(lbCPF, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 110, 60, -1));

        lbNome.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbNome.setText("Nome:");
        pnNovoPaciente.add(lbNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 70, 60, -1));

        lbCSC.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbCSC.setText("Cartão de Saúde do Cidadão:");
        pnNovoPaciente.add(lbCSC, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 190, 258, -1));

        lbRG.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbRG.setText("RG:");
        pnNovoPaciente.add(lbRG, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 110, 70, -1));

        lbNumero.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbNumero.setText("Número:");
        pnNovoPaciente.add(lbNumero, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 340, 75, -1));

        lbRua.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbRua.setText("Rua:");
        pnNovoPaciente.add(lbRua, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 300, 60, -1));

        lbComplemento.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbComplemento.setText("Complemento:");
        pnNovoPaciente.add(lbComplemento, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 340, 132, -1));

        lbBairro.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbBairro.setText("Bairro:");
        pnNovoPaciente.add(lbBairro, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 380, 70, -1));

        lbCidade.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbCidade.setText("Cidade:");
        pnNovoPaciente.add(lbCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 420, 70, -1));

        lbCEP.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbCEP.setText("CEP:");
        pnNovoPaciente.add(lbCEP, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 380, 60, -1));

        lbEstado.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbEstado.setText("Estado:");
        pnNovoPaciente.add(lbEstado, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 420, 132, -1));

        lbEndereco.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Papyrus", 0, 11), new java.awt.Color(0, 51, 0))); // NOI18N
        pnNovoPaciente.add(lbEndereco, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 250, 750, 240));
        pnNovoPaciente.add(txRua, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 300, 580, -1));
        pnNovoPaciente.add(txNumero, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 340, 210, -1));
        pnNovoPaciente.add(txBairro, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 380, 290, -1));
        pnNovoPaciente.add(txComplemento, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 340, 190, -1));
        pnNovoPaciente.add(txCEP, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 380, 190, -1));

        cbCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Rio de Janeiro" }));
        pnNovoPaciente.add(cbCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 420, 310, -1));

        cbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Rio de Janeiro" }));
        pnNovoPaciente.add(cbEstado, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 420, 140, -1));
        pnNovoPaciente.add(txNome, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 70, 580, -1));
        pnNovoPaciente.add(txCSC, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 190, 220, -1));
        pnNovoPaciente.add(txCPF, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 110, 210, -1));
        pnNovoPaciente.add(txRG, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 110, 190, -1));

        btCadastrarDigital.setFont(new java.awt.Font("Tahoma", 0, 12));
        btCadastrarDigital.setText("Cadastrar Digital");
        btCadastrarDigital.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCadastrarDigitalActionPerformed(evt);
            }
        });
        pnNovoPaciente.add(btCadastrarDigital, new org.netbeans.lib.awtextra.AbsoluteConstraints(870, 210, 190, 40));

        lbDataNascimento.setFont(new java.awt.Font("Papyrus", 1, 16));
        lbDataNascimento.setText("Data de Nascimento:");
        pnNovoPaciente.add(lbDataNascimento, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 150, 170, -1));

        lbDadosPessoais1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados Pessoais", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Papyrus", 0, 11), new java.awt.Color(0, 51, 0))); // NOI18N
        pnNovoPaciente.add(lbDadosPessoais1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 20, 750, 230));

        lbImpressaoDigital.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Impressão Digital", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Papyrus", 0, 11), new java.awt.Color(0, 51, 0))); // NOI18N
        pnNovoPaciente.add(lbImpressaoDigital, new org.netbeans.lib.awtextra.AbsoluteConstraints(870, 20, 190, 180));

        lbDigital.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/uff/ihc/gui/imagens/digital.png"))); // NOI18N
        pnNovoPaciente.add(lbDigital, new org.netbeans.lib.awtextra.AbsoluteConstraints(950, 80, 40, 40));

        lbAviso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/uff/ihc/gui/imagens/aviso.png"))); // NOI18N
        pnNovoPaciente.add(lbAviso, new org.netbeans.lib.awtextra.AbsoluteConstraints(950, 80, 40, 40));

        lbMsgAviso.setText("Não há digital cadastrada.");
        pnNovoPaciente.add(lbMsgAviso, new org.netbeans.lib.awtextra.AbsoluteConstraints(890, 130, 160, -1));

        lbMsgDigital.setText("Digital cadastrada.");
        pnNovoPaciente.add(lbMsgDigital, new org.netbeans.lib.awtextra.AbsoluteConstraints(920, 130, -1, -1));

        btSalvar.setFont(new java.awt.Font("DejaVu Sans", 0, 13));
        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/uff/ihc/gui/imagens/salvar.png"))); // NOI18N
        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        pnNovoPaciente.add(btSalvar, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 490, 110, 40));
        pnNovoPaciente.add(dtDataNascimento, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 150, 130, -1));

        pnPrincipal.add(pnNovoPaciente, new org.netbeans.lib.awtextra.AbsoluteConstraints(149, 60, 1180, 550));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbRotuloUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 733, Short.MAX_VALUE)
                .addComponent(lbData, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(pnPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 1453, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(33, Short.MAX_VALUE)
                .addComponent(pnPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 638, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbRotuloUsuario)
                    .addComponent(lbNomeUsuario)
                    .addComponent(lbData))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void OnNovoPaciente(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_OnNovoPaciente
        pnBTBuscarPaciente.setBackground(new Color(0, 51, 0));
        pnBTNovoPaciente.setBackground(Color.WHITE);
        pnBTNovoPaciente.getComponent(0).setForeground(Color.BLACK);
        pnBTBuscarPaciente.getComponent(0).setForeground(Color.WHITE);
        pnBTNovoPaciente.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.BLACK));
        pnNovoPaciente.setVisible(true);
        pnBuscarPaciente.setVisible(false);
        lbMsgDigital.setVisible(false);
        lbDigital.setVisible(false);
        lbMsgAviso.setVisible(true);
        lbAviso.setVisible(true);
    }//GEN-LAST:event_OnNovoPaciente

    private void pnBTBuscarPacienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnBTBuscarPacienteMouseClicked
        pnBTNovoPaciente.setBackground(new Color(0, 51, 0));
        pnBTBuscarPaciente.setBackground(Color.WHITE);
        pnBTBuscarPaciente.getComponent(0).setForeground(Color.BLACK);
        pnBTNovoPaciente.getComponent(0).setForeground(Color.WHITE);
        pnBTBuscarPaciente.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 0, Color.BLACK));
        pnBuscarPaciente.setVisible(true);
        pnNovoPaciente.setVisible(false);
        setDadosPessoaisVisiveis(false);
    }//GEN-LAST:event_pnBTBuscarPacienteMouseClicked

    private void btCadastrarDigitalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCadastrarDigitalActionPerformed
        Leitura ld = new Leitura();
        // ld.dispose();
        //  ld.setUndecorated(true);
        ld.setVisible(true);
//        wait(3);

        lbMsgAviso.setVisible(false);
        lbAviso.setVisible(false);
        lbMsgDigital.setVisible(true);
        lbDigital.setVisible(true);
        // ld.setVisible(false);
    }//GEN-LAST:event_btCadastrarDigitalActionPerformed

    private void btLeituraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLeituraActionPerformed
        Leitura ld = new Leitura();
        // ld.dispose();
        //  ld.setUndecorated(true);
        ld.setVisible(true);
        preenchePaciente();
        setDadosPessoaisVisiveis(true);
    }//GEN-LAST:event_btLeituraActionPerformed

    private void btCartaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCartaoActionPerformed
        BuscarCartaoSaude busca = new BuscarCartaoSaude(this);
        busca.setTabela(getPacientes());
        busca.setVisible(true);
      

        setDadosPessoaisVisiveis(true);
    }//GEN-LAST:event_btCartaoActionPerformed

    private void btConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConfirmarActionPerformed
        TelaPerfilPaciente perfil = new TelaPerfilPaciente(nome);
        perfil.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        perfil.setPaciente(getP());
        perfil.setVisible(true);
        

    //  p =  paciente.buscarPaciente(txNome1.getText(), txCPF1.getText(), txRG1.getText(), dtDataNascimento1.getDate(), txNumero.getText());

    }//GEN-LAST:event_btConfirmarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        JOptionPane.showMessageDialog(null, "Paciente salvo com sucesso!");
        limparCamposNovoPaciente();
    }//GEN-LAST:event_btSalvarActionPerformed

    public void setDadosPessoaisVisiveis(boolean b) {
        lbNome1.setEnabled(b);
        txNome1.setEnabled(b);
        lbCPF1.setEnabled(b);
        txCPF1.setEnabled(b);
        lbRG1.setEnabled(b);
        txRG1.setEnabled(b);
        lbDadosPessoais.setEnabled(b);
        lbDataNascimento1.setVisible(b);
        dtDataNascimento1.setEnabled(b);
        lbCSC1.setEnabled(b);
        txCSC1.setEnabled(b);
    }

    public void limparCamposNovoPaciente() {
        txNome.setText("");
        txCPF.setText("");
        txRG.setText("");
        dtDataNascimento.setDate(null);
        txCSC.setText("");
        txRua.setText("");
        txNumero.setText("");
        txComplemento.setText("");
        txBairro.setText("");
        txCEP.setText("");
        cbEstado.setSelectedIndex(-1);
        cbCidade.setSelectedIndex(-1);

        lbMsgAviso.setVisible(true);
        lbAviso.setVisible(true);
        lbMsgDigital.setVisible(false);
        lbDigital.setVisible(false);
    }

    public void preenchePaciente() {
    Random r= new Random();
    int codigo = r.nextInt(getPacientes().getListaPacientes().size()-1);
        setP(getPacientes().getListaPacientes().get(codigo));

    txNome1.setText(getP().getNome());
    txCPF1.setText(getP().getCpf());
    txRG1.setText(getP().getRg());
    dtDataNascimento1.setDate(getP().getDataNascimento());
    txCSC1.setText(getP().getNumeroCartaoSaude());


    }
  public void preenchePaciente(Paciente p) {
    txNome1.setText(p.getNome());
    txCPF1.setText(p.getCpf());
    txRG1.setText(p.getRg());
    dtDataNascimento1.setDate(p.getDataNascimento());
    txCSC1.setText(p.getNumeroCartaoSaude());


    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                TelaPacientes tela = new TelaPacientes("");
                tela.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCadastrarDigital;
    private javax.swing.JButton btCartao;
    private javax.swing.JButton btConfirmar;
    private javax.swing.JButton btLeitura;
    private javax.swing.JButton btSalvar;
    private javax.swing.JComboBox cbCidade;
    private javax.swing.JComboBox cbEstado;
    private com.toedter.calendar.JDateChooser dtDataNascimento;
    private com.toedter.calendar.JDateChooser dtDataNascimento1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JLabel lbAviso;
    private javax.swing.JLabel lbBairro;
    private javax.swing.JLabel lbBuscarPaciente;
    private javax.swing.JLabel lbCEP;
    private javax.swing.JLabel lbCPF;
    private javax.swing.JLabel lbCPF1;
    private javax.swing.JLabel lbCSC;
    private javax.swing.JLabel lbCSC1;
    private javax.swing.JLabel lbCidade;
    private javax.swing.JLabel lbComplemento;
    private javax.swing.JLabel lbDadosPessoais;
    private javax.swing.JLabel lbDadosPessoais1;
    private javax.swing.JLabel lbData;
    private javax.swing.JLabel lbDataNascimento;
    private javax.swing.JLabel lbDataNascimento1;
    private javax.swing.JLabel lbDigital;
    private javax.swing.JLabel lbEndereco;
    private javax.swing.JLabel lbEstado;
    private javax.swing.JLabel lbImpressaoDigital;
    private javax.swing.JLabel lbMsgAviso;
    private javax.swing.JLabel lbMsgDigital;
    private javax.swing.JLabel lbNome;
    private javax.swing.JLabel lbNome1;
    private javax.swing.JLabel lbNomeUsuario;
    private javax.swing.JLabel lbNonoPaciente;
    private javax.swing.JLabel lbNumero;
    private javax.swing.JLabel lbRG;
    private javax.swing.JLabel lbRG1;
    private javax.swing.JLabel lbRotuloUsuario;
    private javax.swing.JLabel lbRua;
    private javax.swing.JPanel pnBTBuscarPaciente;
    private javax.swing.JPanel pnBTNovoPaciente;
    private javax.swing.JPanel pnBuscarPaciente;
    private javax.swing.JPanel pnNovoPaciente;
    private javax.swing.JPanel pnPrincipal;
    private javax.swing.JTextField txBairro;
    private javax.swing.JTextField txCEP;
    private javax.swing.JTextField txCPF;
    private javax.swing.JTextField txCPF1;
    private javax.swing.JTextField txCSC;
    private javax.swing.JTextField txCSC1;
    private javax.swing.JTextField txComplemento;
    private javax.swing.JTextField txNome;
    private javax.swing.JTextField txNome1;
    private javax.swing.JTextField txNumero;
    private javax.swing.JTextField txRG;
    private javax.swing.JTextField txRG1;
    private javax.swing.JTextField txRua;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the pacientes
     */
    public TB_Paciente getPacientes() {
        return pacientes;
    }

    /**
     * @param pacientes the pacientes to set
     */
    public void setPacientes(TB_Paciente pacientes) {
        this.pacientes = pacientes;
    }

    /**
     * @return the p
     */
    public Paciente getP() {
        return p;
    }

    /**
     * @param p the p to set
     */
    public void setP(Paciente p) {
        this.p = p;
    }
}
